<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户登录 - Cloud DMS</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-src/dist/css/layui.css">
    <style>
        body {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            font-family: 'Arial', sans-serif;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .login-container {
            width: 420px;
            padding: 40px;
            background-color: rgba(255, 255, 255, 0.95);
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.1);
            backdrop-filter: blur(10px);
        }
        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-title {
            font-size: 28px;
            font-weight: bold;
            color: #4A90E2;
            margin-bottom: 8px;
        }
        .login-subtitle {
            font-size: 14px;
            color: #666;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .user-icon {
            width: 20px;
            height: 20px;
            background: #4A90E2;
            border-radius: 50%;
            margin-right: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 12px;
        }
        .layui-form-item {
            margin-bottom: 20px;
        }
        .layui-form-label {
            width: 80px;
            font-weight: 500;
            color: #333;
        }
        .layui-input-block {
            margin-left: 100px;
        }
        .layui-input {
            height: 44px;
            line-height: 44px;
            padding: 0 15px;
            border: 2px solid #e8e8e8;
            border-radius: 8px;
            transition: border-color 0.3s;
        }
        .layui-input:focus {
            border-color: #4A90E2;
            box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.1);
        }
        .layui-btn {
            width: 100%;
            height: 44px;
            line-height: 44px;
            background: linear-gradient(135deg, #4A90E2 0%, #357ABD 100%);
            border: none;
            border-radius: 8px;
            color: #fff;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
        }
        .layui-btn:hover {
            background: linear-gradient(135deg, #357ABD 0%, #2E5E95 100%);
            transform: translateY(-1px);
            box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
        }
        .login-footer {
            text-align: center;
            margin-top: 20px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        .admin-link {
            color: #666;
            text-decoration: none;
            font-size: 14px;
            transition: color 0.3s;
        }
        .admin-link:hover {
            color: #4A90E2;
        }
        .feature-tags {
            display: flex;
            justify-content: center;
            gap: 8px;
            margin-top: 15px;
            flex-wrap: wrap;
        }
        .feature-tag {
            background: rgba(74, 144, 226, 0.1);
            color: #4A90E2;
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
        }
    </style>
</head>
<body>
<div class="login-container layui-form" action="">
    <div class="login-header">
        <div class="login-title">Cloud DMS</div>
        <div class="login-subtitle">
            <div class="user-icon">👤</div>
            用户登录
        </div>
        <div class="feature-tags">
            <span class="feature-tag">文件管理</span>
            <span class="feature-tag">安全存储</span>
            <span class="feature-tag">便捷分享</span>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-block">
            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" lay-submit lay-filter="user-login">登录</button>
    </div>
    
    <div class="login-footer">
        <a href="/auth/register" class="admin-link" style="margin-right: 20px;">📝 免费注册账号</a>
        <a href="/auth/admin-login" class="admin-link">🔒 管理员登录入口</a>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/layui-src/dist/layui.js"></script>
<script>
    layui.use(['form', 'layer'], function(){
        var form = layui.form;

        // 用户登录表单验证
        form.on('submit(user-login)', function(data){
            var username = data.field.username;
            var password = data.field.password;

            // 发送Ajax请求到服务器进行用户登录验证
            layui.jquery.ajax({
                url: '/auth/user-login',
                type: 'POST',
                contentType: 'application/json',
                data: JSON.stringify({
                    username: username,
                    password: password
                }),
                success: function(response) {
                    if (response.success) {
                        // 存储JWT Token到localStorage
                        if (response.token) {
                            localStorage.setItem('token', response.token);
                        }
                        layui.layer.msg(response.message, {icon: 1, time: 1500}, function() {
                            window.location.href = response.redirectUrl;
                        });
                    } else {
                        layui.layer.msg(response.message, {icon: 2, time: 3000});
                    }
                },
                error: function() {
                    layui.layer.msg('网络连接异常，请稍后再试', {icon: 2, time: 3000});
                }
            });

            return false; // 阻止表单跳转
        });
    });
</script>
</body>
</html>